package com.momo.mal.anime.overall;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import net.momo.mal.R;
import com.momo.mal.anime.adapter.AnimeListAdapter;
import com.momo.mal.anime.view.AnimeView;
import com.momo.mal.database.MalDatabaseAdapter;
import com.momo.mal.entity.Anime;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AnimeTabPlanToWatch extends Fragment {
	private ListView listView;
	private String mContent = "???";
	private int sort;

	private static final String KEY_CONTENT = "AnimeTabPlanToWatch:Content";

	public static AnimeTabPlanToWatch newInstance(int sort) {
		AnimeTabPlanToWatch fragment = new AnimeTabPlanToWatch();
		fragment.sort = sort;

		return fragment;
	}

//	@Override
//	public void onPause() {
//		super.onPause();
//	}
//
//	@Override
//	public void onResume() {
//		super.onResume();
//	}
	
//	public void updateData(int sort) {
//		listView.removeAllViews();
//		animes = new ArrayList<Anime>();
//		animes.addAll(getAnimeComplete(sort));
//		adapter.notifyDataSetChanged();
//	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if ((savedInstanceState != null)
				&& savedInstanceState.containsKey(KEY_CONTENT)) {
			mContent = savedInstanceState.getString(KEY_CONTENT);
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.anime_overall_tab, null);

		List<Anime> animes = new ArrayList<Anime>();
		animes.addAll(getAnimeComplete(sort));

		AnimeListAdapter adapter = new AnimeListAdapter(getActivity(), animes);
		listView = (ListView) view.findViewById(R.id.list_anime);
		listView.setAdapter(adapter);

		return view;
	}

	private List<Anime> getAnimeComplete(int sort) {
		List<Anime> animes = new ArrayList<Anime>();
		MalDatabaseAdapter dbAdapter = new MalDatabaseAdapter(getActivity());
		animes.addAll(dbAdapter.getAnimeOverall("plantowatch", sort));

		return animes;
	}
}
